package demo5;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class CglibInterceptor implements MethodInterceptor {
    @Override
    // public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        // Object res=method.invoke(target,args);//JDK 执行目标对象的指定的方法
        book();
        Object res = methodProxy.invokeSuper(o,objects); //cglib  invokeSuper 去调用父类的执行方法
        after();
        return "Cglib得到返回值: "+ res;
    }

    public void book(){
        System.out.println("打电话预约售楼部美女");
    }

    public void after(){
        System.out.println("电话持续跟踪买家意向");
    }
}
